package com.wenxixuanwu.fruitstore.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;



@RestController
public class UrlController {
    private static String dirPath = "D:/fruitstoreimg";
    @RequestMapping("upload")
    public String upload(MultipartFile picFile) throws IOException {
        String FileName = picFile.getOriginalFilename();
        String suffix = FileName.substring(FileName.lastIndexOf("."));
        FileName = UUID.randomUUID() + suffix;
        File dirFile = new File(dirPath);
        if (!dirFile.exists()) {
            dirFile.mkdirs();
        }
        String filePath = dirPath + "/" + FileName;
        picFile.transferTo(new File(filePath));
        return "/" + FileName;
    }

    @RequestMapping("/remove")
    public void remove(String name) {
        String filePath = dirPath + name;
        new File(filePath).delete();
    }
}
